package com.domino.client.view;

import com.domino.shared.model.Brick;
import com.domino.shared.model.Color;
import com.domino.shared.model.Point;
import com.google.gwt.user.client.ui.ListBox;

public class RoundNumberListBox extends ListBox {
	
	int roundNumber = 0;
	
	public RoundNumberListBox() {
		addItem("------ Start ------");
		addCurrentRound();
	} 
	
	public void addRound(Brick brick) {
		roundNumber++;
		String item = Integer.toString(roundNumber) + " " + brick.getColor().name() + " " + getPoint(brick.getPoint());
		this.setItemText(roundNumber, item);
		addCurrentRound();
	}

	private String getPoint(Point point) {
		return point==null ? "pass" : Integer.toString(point.getX()+1) + ":" + Integer.toString(point.getY()+1);
	}

	private void addCurrentRound() {
		String item;
		item = Integer.toString(roundNumber+1) + ">>>";
		addItem(item);
		setSelectedIndex(roundNumber+1);
	}

	public void setFinished() {
		removeItem(roundNumber+1);
		setSelectedIndex(roundNumber);
	}

	public void removeListRound() {
		int index = getItemCount()-1;
		if (index>=0) {
			removeItem(index);
		}
	}

	
	

}
